/* internal.h: internal headers */

#ifdef FONTMAN_BACKEND_ATS
#include <Carbon/Carbon.h>
#define FONTMAN_OUTPUT_ENCODING     kCFStringEncodingUTF8
#endif

#ifdef FONTMAN_BACKEND_FC
#include <fontconfig/fontconfig.h>
#endif

#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_SFNT_NAMES_H
#include FT_TRUETYPE_IDS_H
#include <iconv.h>

/* FIXME: only available to POSIX systems */
#include <fnmatch.h>

/* The font management context */
typedef struct _fontman_list_t {
    enum fontman_list_type type;
    
    union {
#ifdef FONTMAN_BACKEND_ATS
        ATSFontIterator iterator;
#endif
#ifdef FONTMAN_BACKEND_FC
        struct {
            FcFontSet *list;
            int count;
        } fc;
#endif
        DIR *dirp;
    } u;

    FT_Library   lib;
    const char  *path;
    const char  *pattern;
    unsigned int flags;
} fontman_list_t;

enum fontman_sfnt_name_entry {
    FONTMAN_SFNT_ALL = -1, 
    FONTMAN_SFNT_END = -2
};

enum fontman_encoding {
    FONTMAN_ENC_UTF16BE, 
    FONTMAN_ENC_GBK, 
    FONTMAN_ENC_UTF16LE,
    FONTMAN_ENC_BIG5,
};

struct fontman_sfnt_name {
    int platform_id;                /* we use int instead of FT_UShort to */
    int encoding_id;                /* allow an extra -1 as wildcard */
    int language_id;
    int name_id;
    enum fontman_encoding enc_id;   /* the encoding we use to convert */
};

int convert_sfnt_name(char *dest_name, 
                      const char *sfnt_name, 
                      int sfnt_name_len, 
                      enum fontman_encoding enc_id);

int fontman_get_font_info(FT_Library *lib, 
                          fontman_face_t *face, 
                          unsigned int flags);

void init_info_charmaps(fontman_info_t *info);
void free_info_charmaps(fontman_info_t *info);

